home *** CD-ROM | disk | FTP | other *** search
/ PC World 2006 February / PCWorld_2006-02_cd.bin / software / vyzkuste / triky / triky.exe / httrack-3.33.exe / {app} / src / htsthread.h < prev    next >
C/C++ Source or Header  |  2005-02-05  |  4KB  |  119 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: Threads                                                */
  34. /* Author: Xavier Roche                                         */
  35. /* ------------------------------------------------------------ */
  36.  
  37. #ifndef HTS_DEFTHREAD
  38. #define HTS_DEFTHREAD
  39.  
  40. #include "htsglobal.h"
  41. #if USE_PTHREAD
  42. #include <pthread.h>    /* _beginthread, _endthread */
  43. #endif
  44. #if HTS_WIN
  45. #include "windows.h"
  46. #ifdef _WIN32_WCE
  47. #ifndef HTS_CECOMPAT
  48. #include "cethread.h"
  49. #endif
  50. #endif
  51. #endif
  52.  
  53. #if USE_BEGINTHREAD
  54. #if HTS_WIN
  55.  
  56. #define PTHREAD_RETURN
  57. #define PTHREAD_TYPE void
  58. #define PTHREAD_TYPE_FNC __cdecl
  59. #define PTHREAD_LOCK_TYPE HANDLE
  60. #define PTHREAD_HANDLE HANDLE
  61. #define PTHREAD_WAIT_THREAD(A) do { WaitForSingleObject(A, INFINITE); CloseHandle(A); } while(0)
  62.  
  63.  
  64. /* Useless - see '__declspec( thread )' */
  65. /*
  66. #define PTHREAD_KEY_TYPE void*
  67. #define PTHREAD_KEY_CREATE(ptrkey, uninit)      do { *(ptrkey)=(void*)NULL; } while(0)
  68. #define PTHREAD_KEY_DELETE(key)                 do { key=(void*)NULL; } while(0)
  69. #define PTHREAD_KEY_SET(key, val, ptrtype)      do { key=(void*)(val); } while(0)
  70. #define PTHREAD_KEY_GET(key, ptrval, ptrtype)   do { *(ptrval)=(ptrtype)(key); } while(0)
  71. */
  72.  
  73. #else
  74.  
  75. #define PTHREAD_RETURN NULL
  76. #define PTHREAD_TYPE void*
  77. #define PTHREAD_TYPE_FNC
  78. #define PTHREAD_LOCK_TYPE pthread_mutex_t
  79. #define PTHREAD_KEY_TYPE pthread_key_t
  80. #define PTHREAD_KEY_CREATE(ptrkey, uninit)      pthread_key_create(ptrkey, uninit)
  81. #define PTHREAD_KEY_DELETE(key)                 pthread_key_delete(key)
  82. #define PTHREAD_KEY_SET(key, val, ptrtype)      pthread_setspecific(key, (void*)val)
  83. #define PTHREAD_KEY_GET(key, ptrval, ptrtype)   do { *(ptrval)=(ptrtype)pthread_getspecific(key); } while(0)
  84. #define PTHREAD_HANDLE pthread_t
  85. #define PTHREAD_WAIT_THREAD(A) do { pthread_join(A, NULL); CloseHandle(A); } while(0)
  86.  
  87. #endif
  88.  
  89. #else
  90.  
  91. #define PTHREAD_LOCK_TYPE void*
  92. #define PTHREAD_KEY_TYPE void*
  93. #define PTHREAD_KEY_CREATE(ptrkey, uninit)      do { *(ptrkey)=(void*)NULL; } while(0)
  94. #define PTHREAD_KEY_DELETE(key)                 do { key=(void*)NULL; } while(0)
  95. #define PTHREAD_KEY_SET(key, val, ptrtype)      do { key=(void*)(val); } while(0)
  96. #define PTHREAD_KEY_GET(key, ptrval, ptrtype)   do { *(ptrval)=(ptrtype)(key); } while(0)
  97. #define PTHREAD_HANDLE void
  98.  
  99. #endif
  100.  
  101. /* Library internal definictions */
  102. HTSEXT_API int hts_newthread( PTHREAD_TYPE ( PTHREAD_TYPE_FNC *start_address )( void * ), unsigned stack_size, void *arglist );
  103. HTSEXT_API void htsthread_wait(void );
  104. HTSEXT_API void htsthread_wait_n(int n_wait);
  105.  
  106. #ifdef HTS_INTERNAL_BYTECODE
  107. HTSEXT_API int htsSetLock(PTHREAD_LOCK_TYPE * hMutex,int lock);
  108. HTSEXT_API void htsthread_init(void );
  109. HTSEXT_API void htsthread_uninit(void );
  110.  
  111. #if USE_PTHREAD
  112. // unsigned long _beginthread( void* ( *start_address )( void * ), unsigned stack_size, void *arglist );
  113.  
  114. #endif
  115. #endif
  116.  
  117. #endif
  118.  
  119.